import UserModel from "../../../models/User";

const userModel = new UserModel()

Page({
  data: {
    received_id: '',
    amount: 0
  },

  bindReceived(e) {
    this.setData({ received_id: e.detail.value.trim() })
  },

  bindAmount(e) {
    this.setData({ amount: e.detail.value.trim()})
  },

  onSave() {
    if (!this.data.received_id) {
      return wx.showToast({title: '请输入接收者ID', icon: 'error', mask: true})
    }
    if (!this.data.amount) {
      return wx.showToast({title: '请输转出金额', icon: 'error', mask: true})
    }
    if (isNaN(+this.data.amount) || +this.data.amount <= 0) {
      return wx.showToast({title: '金额错误', icon: 'error', mask: true})
    }

    userModel.onTransfer({ ...this.data }).then(() => {
      wx.showModal({title: '操作成功', success: () => {
          wx.switchTab({
            url: '/pages/center/index'
          })
        }})
    })
  }

});
